package com.easysoft.framework.casereply.service;

import com.easysoft.commons.utils.UUIDUtils;
import com.easysoft.framework.annotation.jdbc.DataSource;
import com.easysoft.framework.beans.Page;
import com.easysoft.framework.casereply.mapper.SysCasemanagementMapperExtd;
import com.easysoft.framework.casereply.mapper.SysCasematerialMapperExtd;
import com.easysoft.framework.casereply.model.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by try on 2017/9/13.
 */
@Service("service.SysCasematerialService")
public class SysCasematerialService {
    @Autowired
    @Qualifier("mapper.SysCasematerialMapperExtd")
    private SysCasematerialMapperExtd sysCasematerialMapperExtd;

    @DataSource(DataSource.MASTER)
    public int addSysCasematerial(SysCasematerial sysCasematerial){
        sysCasematerial.setId(UUIDUtils.getUUID());
        return sysCasematerialMapperExtd.insertSelective(sysCasematerial);
    }

    @DataSource(DataSource.MASTER)
    public int deleteSysCasematerial(String id){
        return sysCasematerialMapperExtd.deleteByPrimaryKey(id);
    }

    @DataSource(DataSource.MASTER)
    public int updateSysCasematerial(SysCasematerial sysCasematerial){
        return sysCasematerialMapperExtd.updateByPrimaryKeySelective(sysCasematerial);
    }

    public SysCasematerial selectSysCasematerialById(String id){
        return sysCasematerialMapperExtd.selectByPrimaryKey(id);
    }

    @DataSource(DataSource.SLAVE)
    public List<SysCasematerialView> selectSysCasematerialListByPage(SysCasematerialQuery query, Page page){
        int maxRow = sysCasematerialMapperExtd.selectCountSysCasematerial(query);
        page.setMaxRow(maxRow);

        if (maxRow == 0) {
            return new ArrayList<SysCasematerialView>();
        }

        return sysCasematerialMapperExtd.selectSysCasematerialListByPage(query,page);
    }
}
